#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define BP_SZ 100
typedef struct{
    char token[120];
    int syn;
}Bingp;
char source[1000000];
char *rwtab[27] = {“main”,”if”,”then”,”while”,”do”,”static”,”int”,”double”,”struct”,”break”,”else”,”long”,”switch”,”case”,”typedef”,”char”,”return”,”const”,”float”,”short”,”continue”,”for”,”void”,”default”,”sizeof”,”do”};

Bingp bp[BP_SZ];

int search(){
    int i, j = 0, k;
    int tag = 0;
    int lens = strlen(source);
    char s[120];
    memset(bp, 0, sizeof(bp));
    bp[44] = {{"main", 1}, {"if",2}, {"then", 3},{"while",4},{"do", 5},{"static",6},{"ID",25},{"NUM",26},{"+",27},{"-",28},
                 {"*", 29}, {"/", 30},{":", 31},{"<",33},{"!=",34},{"<=",35},{">",36},{">=",37},{"=",38},{"default",39},
                 {";",41},{"(",42},{")",43},{"int",7},{"double",8},{"struct",9},{"break",10},{"else",11},{"long",12},{"switch",13},
                 {"case",14},{"typedef",15},{"char",16},{"return",17},{"const",18},{"float",19},{"short",20},{"continue",21},{"for",22},
                 {"do",40},{"sizeof",24},{"#",0}};
    for(i = 0; i < lens; ++i){
        if(isalpha(source[i])){    
             s[j++] = source[i];      
             while(isalnum(source[i]) || source[i] == '_'){
                  s[j++] = source[i];
                  i++;
             }
             s[j++] = '\0';
             i--;
             for(k = 0; k < 27; k++){
                 if(!strcmp(s, rwtab[k])) {
                      printf("< %s, %d >\n", s,k);
                      tag = 1;
                 }
             }
             if(tag != 1) printf("< %s, - >\n", s);
             j = 0;
             tag = 0;
        }
        else if(isdigit(source[i])){
            s[j++] = source[i];
            while(isdigit(source[i]) || source[i] == '.'){
                if(isdigit(source[i]){
                     s[j++] = source[i];
                }
                else if(source[i] == '.' && !tag){
                     if(isdigit(source[i+1])){
                         s[j++] = source[i];
                         tag = 1;
                     }
                }
                else if(source[i] == '.' && tag == 1){
                     pirintf("错误的输入格式");
                     return 0;
                }
                i++;
            }          
            s[j++] = '\0';
            i--; 
            if(tag == 1) printf("< %s, float >\n", s);
            else printf("< %s, int >\n", s);
            j = 0;
            tag = 0;
        }
        else if(source[i] == '+'){
            s[j++] = source[i];
            if(source[i+1] == '='){
                s[j++] = '=';
                tag = 1;
            }
            s[j++] = '\0';
            if(tag == 1) printf("< %s, 41 >\n");
            else printf("< %s, 29 >\n");
            j = 0; 
            tag = 0;
        }
        else if(source[i] == '('){
            printf("< (, 42 >\n");
        }
        else if(source[i] == '\32'){
        }
    }
}

